package com.zrrd.config;

import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;

/**
 * @author WanJl
 * @version 1.0
 * @title ServletContainersInitConfig
 * @description Web容器配置类(也叫SpringMVC容器配置类、也叫Servlet容器配置类)
 * 配置它，是因为要设置SpringMVC的请求拦截路径，配置有哪些请求是要经过SpringMVC进行处理的
 * @create 2024/1/27 15:10
 */
public class ServletContainersInitConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringConfig.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{SpringMvcConfig.class};
    }

    @Override
    protected String[] getServletMappings() {

        return new String[]{"/"};
    }
    //解决乱码问题
    @Override
    protected Filter[] getServletFilters() {
        //创建字符集过滤器对象
        CharacterEncodingFilter filter=new CharacterEncodingFilter();
        // 设置字符集
        filter.setEncoding("UTF-8");
        //新建一个父类过滤器对象，把字符集过滤器对象传入，并返回给Web容器
        return new Filter[]{filter};
    }

}
